package com.mashibing.singleton;

/**
 * Lazy loading
 * 懒汉式：什么时候用，什么时候初始化
 * 非线程安全
 * @author: Yuanzt
 * @Date: 2021/3/8
 */
public class Mgr03 {

    private static Mgr03 INSTANCE;

    private Mgr03(){}

    public static Mgr03 getInstance(){
        if (INSTANCE == null){
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            INSTANCE = new Mgr03();
        }
        return INSTANCE;
    }

    public static void main(String[] args) {
        for (int i=0 ;i<100 ;i++){
            new Thread(()->{
                System.out.println(Mgr03.getInstance().hashCode());
            }).start();
        }
    }
}
